Skip to content

Surface streaming HTTP errors at the function call instead of as first stream item#558

Merged
64bit merged 1 commit into
64bit:mainfrom
max-zheng:max/eager_stream_error
May 22, 2026
Merged

Surface streaming HTTP errors at the function call instead of as first stream item#558
64bit merged 1 commit into
64bit:mainfrom
max-zheng:max/eager_stream_error

Conversation

@max-zheng
Copy link
Copy Markdown
Contributor

@max-zheng max-zheng commented May 21, 2026

Surfaces non-2xx HTTP responses as Err(OpenAIError::ApiError(_)) from the streaming methods (post_stream, post_stream_mapped_raw_events, get_stream) instead of delivering them as the first item of the returned stream. Centralizes the status check in execute_response so all callers (unary and streaming) share one code path for "non-2xx → error."

Closes #553.

Changes

  • execute_response now bails with read_error_response(response).await on non-success status, so every downstream caller sees only 2xx responses.
  • New read_error_response helper consumes a non-2xx response and produces the matching OpenAIError::ApiError(ApiErrorResponse { .. }). It's the single source of truth for HTTP error construction — previously this logic was duplicated inline in read_response and (incorrectly, via an InvalidArgument fallback) in the wasm stream_mapped_raw_events.
  • read_response, execute_stream, execute_stream_mapped_raw_events, and both stream_mapped_raw_events impls drop their now-redundant local status checks.
  • Removes the OpenAIError::InvalidArgument(...) fallback from the wasm streaming path (per maintainer feedback on Title: create_stream* methods return Ok(stream) on HTTP error; error surfaces as first stream item instead of as Err from the call #553InvalidArgument is reserved for client-side validation).

Copy link
Copy Markdown
Owner

@64bit 64bit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so nice, thank you!

@64bit 64bit merged commit f6a31a8 into 64bit:main May 22, 2026
103 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Title: create_stream* methods return Ok(stream) on HTTP error; error surfaces as first stream item instead of as Err from the call

2 participants